﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Chapter39.HandlerSample
{
    /// <summary>
    /// SampleHandler 的摘要说明
    /// </summary>
    public class SampleHandler : IHttpHandler
    {
        private string responseString = @"
<!DOCTYPE HTML>
<html>
<head>
    <meta charset=""UTF-8"">
    <title>Sample Handler</title>
</head>
<body>
    <h1>Hello from the custom handler</h1>
    <div>{0}</div>
</body>
</html>";

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("Hello World");
            var request = context.Request;
            var response = context.Response;
            response.ContentType = "text/html";
            response.Write(string.Format(responseString, request.UserAgent));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}